<template>
	<view class="">
		<u-field v-model="wxn" label="微信号" placeholder="请填写微信号">
			<u-button size="mini" slot="right" type="success" @click="upNic">点击修改</u-button>
		</u-field>
		<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wxn: '',
				id: getApp().globalData.user._id,
			}
		},
	
		methods: {
			codeChange() {
				this.wxn = ''
			},
	
	
			upNic() {
				if (this.wxn) {
					uni.showLoading({
						title: '更新中'
					})
					const db = uniCloud.database()
					db.collection('users').doc(this.id).update({
						wxNumber: this.wxn,
					}).then(res => {
						uni.hideLoading();
						uni.showToast({
							title: '更新成功'
						})
					}).catch(err => {
						uni.hideLoading()
						uni.showToast({
							title: '更新失败',
							icon: "error"
						})
					})
				} else {
					uni.showToast({
						icon: 'error',
						title: '请填写后再上传'
					})
				}
			}
		}
	}
</script>

<style>
</style>
